/*
 * RegistrarSession
 * Handles Close and open Regitration
 */
package edu.depaul.se.courseregistration.sessionbean;

import edu.depaul.se.courseregistration.jpa.courses.Section;
import edu.depaul.se.courseregistration.mdb.pubsub.RemindCourseUpdate;
import javax.ejb.EJB;
import javax.ejb.LocalBean;
import javax.ejb.Stateless;

/**
 *
 * @author Group2
 */
@Stateless
@LocalBean
public class RegistrarSession {

    @EJB
    RegistrarEJB registrarEJB;

    @EJB
    CourseEJB courseEJB;
    //RegistrarSession Buisness API
    //Close and Open regiteration
    //@Override
    public int closeSectionRegistration(int sectionId) {
        int result = registrarEJB.closeSectionRegistration(sectionId);//0:success, 1:fail.
        //publish message to course update topic
        if (result == 0) {
            RemindCourseUpdate.publishTopic("REMINDER: One Section Registration is closed. Students cannot register this section anymore....\n" 
                                           + "Details about this closed section:\n" + courseEJB.findSectionById(sectionId));
        }
        return result;
    }
    //@Override

    public int openSectionRegistration(int sectionId) {
        int result = registrarEJB.openSectionRegistration(sectionId);//0:success, 1:fail.
        //publish message to course update topic
        if (result == 0) {
        RemindCourseUpdate.publishTopic("REMINDER: One Section Registration is open now. Students can register this section from now on....\n" 
                                        + "Details about this opened section:\n" + courseEJB.findSectionById(sectionId));
        }
        return result;
    }
}
